#!/sbin/openrc-run

name="Tang server"
description="Server for binding data to network presence"

: ${tang_port:="7500"}
: ${tang_address:="127.0.0.1"}
: ${socat_address:="tcp-listen:$tang_port,bind=$tang_address,fork"}

command="/usr/bin/socat"
command_user="tang:tang"
command_args="$socat_address exec:/usr/libexec/tangd-wrapper"
command_background="yes"

extra_commands="rotate_keys"
description_rotate_keys="Perform rotation of tang keys"
pidfile="/run/$RC_SVCNAME.pid"

rotate_keys() {
	ebegin "Performing rotation of tang keys"
	su ${command_user%:*} -s /bin/sh -c "/usr/libexec/tangd-rotate-keys -d /var/lib/tang"
	eend $?
}

start_pre() {
	checkpath -d -m 0750 -o $command_user /var/lib/tang
}
